// 定义XsysUserGrid类的构造函数
var XsysUserGrid = function (cfg) {

    // 为了在任何情况下可以获得XsysUserGrid的实例对象
    var me = this;

    // 调用父类构造函数
    XsysUserGrid.superclass.constructor.call(this, Ext.apply({
        url: 'xsys/user/list',
        woIdProperty: 'id',
        woNameProperty: 'loginName',
        woTitle: '用户列表',
        singleSelect: false,
        woPaging : true,
        woColumns: [
                        {
            header: 'ID',
            dataIndex: 'id',
            hidden: true,
            width: 150
        }
                        ,{
            header: '登录名',
            dataIndex: 'loginName',
            hidden: false,
            width: 150
        }
                ,{
            header: '密码',
            dataIndex: 'password',
            hidden: false,
            width: 150
        }
                ,{
            header: '创建时间',
            dataIndex: 'createTime',
            hidden: false,
            width: 150
        }
                ,{
            header: '修改密码时间',
            dataIndex: 'passwordTime',
            hidden: false,
            width: 150
        }
                                , {
            header: '角色ID',
            dataIndex: 'rolesId',
            hidden: true,
            width: 150
        }, {
            header: '角色',
            dataIndex: 'rolesName',
            hidden: false,
            width: 150
        }
                ],
        woButtons: [{
            woButtonType: 'wo.list.create', // 创建按钮
            woForm: XsysUserCreateForm, // 创建表单类
            woGridSelectType: 'singleornone' // 设置列表选择类型：单选或者不选
        }, {
            woButtonType: 'wo.list.delete', // 删除按钮
            woGridSelectType: 'single', // 设置列表选择类型：单选
            woUrl: 'xsys/user/delete' // 设置删除提交url，key值为selectedIds
        }],
        // 查询字段
        woSearchFields: [{
            items: [{
                name: 'searchContent',
                fieldLabel: '查询内容',
                width: 100
            }]
        }],
        woUpdateForm: XsysUserUpdateForm // 设置列表双击时，弹出的修改表单类
    }, cfg));
};
// XsysUserGrid继承Wo.GridPanel
Ext.extend(XsysUserGrid, Wo.GridPanel, {});

Wo.loadJsByClass('XsysRoleGrid');

// 定义用户的创建表单，继承Wo.FormPanel
var XsysUserCreateForm = function (cfg) {
    // 调用父类构造函数
    XsysUserCreateForm.superclass.constructor.call(this, Ext.apply({
        columns: 1,
        url: 'xsys/user/create',
        title: '创建用户',
        width: 400,
        height: 300,
        items: [
    	                {
            items: [{
                name: 'id',
                fieldLabel: 'ID',
                                allowBlank: true,
                width: 200
            }]
        }
                        , {
            items: [{
                name: 'loginName',
                fieldLabel: '登录名',
                allowBlank: true,
                                width: 200
            }]
        }
                , {
            items: [{
                name: 'password',
                fieldLabel: '密码',
                allowBlank: true,
                                width: 200
            }]
        }
                , {
            items: [{
                name: 'createTime',
                fieldLabel: '创建时间',
                allowBlank: true,
                                xtype : 'xdatetime',
                                width: 200
            }]
        }
                , {
            items: [{
                name: 'passwordTime',
                fieldLabel: '修改密码时间',
                allowBlank: true,
                                xtype : 'xdatetime',
                                width: 200
            }]
        }
                                , {
            items: [{
                xtype: 'objectsearch', // 控件类型设置为对象查找
                hiddenName: 'rolesId', // 角色id
                name: 'rolesName', // 角色名称
                fieldLabel: '角色',
                selectLength : -1, // 设置多选
                woPanelClass: 'XsysRoleGrid', // 弹出grid的类
                width: 200
            }]
        }
                ]
    }, cfg));
};
// 继承
Ext.extend(XsysUserCreateForm, Wo.FormPanel, {});

// 定义用户修改表单
var XsysUserUpdateForm = function (cfg) {
    XsysUserUpdateForm.superclass.constructor.call(this, Ext.apply({
        columns: 1,
        url: 'xsys/user/update',
        title: '修改用户',
        width: 400,
        height: 300,
        items: [
    	                {
            items: [{
                name: 'id',
                fieldLabel: 'ID',
                width: 200,
                readOnly: true,
                value: cfg.row.get('id')
            }]
        }
    	    	        , {
            items: [{
                name: 'loginName',
                fieldLabel: '登录名',
                width: 200,
                                allowBlank: true,
                value: cfg.row.get('loginName')
            }]
        }
    	        , {
            items: [{
                name: 'password',
                fieldLabel: '密码',
                width: 200,
                                allowBlank: true,
                value: cfg.row.get('password')
            }]
        }
    	        , {
            items: [{
                name: 'createTime',
                fieldLabel: '创建时间',
                width: 200,
                                xtype : 'xdatetime',
                                allowBlank: true,
                value: cfg.row.get('createTime')
            }]
        }
    	        , {
            items: [{
                name: 'passwordTime',
                fieldLabel: '修改密码时间',
                width: 200,
                                xtype : 'xdatetime',
                                allowBlank: true,
                value: cfg.row.get('passwordTime')
            }]
        }
    	    	    	        , {
            items: [{
                xtype: 'objectsearch', // 控件类型设置为对象查找
                hiddenName: 'rolesId', // 角色id
                name: 'rolesName', // 角色名称
                fieldLabel: '角色',
                value: cfg.row.get('rolesId'),
                woText: cfg.row.get('rolesName'),
                selectLength : -1, // 设置多选
                woPanelClass: 'XsysRoleGrid', // 弹出grid的类
                width: 200
            }]
        }
            	]
    }, cfg));
};
Ext.extend(XsysUserUpdateForm, Wo.FormPanel, {});